import axios from "axios";

const request = axios.create({
  // baseURL: `${import.meta.env.VITE_APP_URI}/api`,
  baseURL: "http://58.215.18.179:28012/api",
  timeout: 9000,
  headers: {
    appid: "13a4d4b8-c321-d882-e436-3693ae4009e4",
    "Content-Type": "application/json",
  },
});

request.interceptors.request.use(
  function (config) {
    config.headers = {
      ...config.headers,
      auth:
        config.headers.auth ||
        "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2ODkxNDAxNDAsImV4cCI6MTY4OTE3NjE0MCwibmJmIjoxNjg5MTQwMTQwLCJvcmdOYW1lIjoi5rGf6Zi05biCIiwiYWNjb3VudE5hbWUiOiJqeWFkbWluIiwiaWRlbnRpeUNvZGUiOiJBRE1JTiIsIm9yZ1BhdGhzIjoiMzIwMjAwLUpUSjEiLCJ1c2VyTmFtZSI6Iuaxn-mYtOW4gueuoeeQhuWRmCIsInVzZXJJZCI6NTMwMSwiaW5uZXIiOmZhbHNlLCJvcmdJZCI6NywidXNlckNvZGUiOiIkVSQxNjQ4NTczNTIwNzQ3MDIzMDEiLCJhY2NvdW50SWQiOjUzMDEsInJlZ2lvbkNvZGUiOiIzMjAyODEiLCJhcHBpZCI6IjEzYTRkNGI4LWMzMjEtZDg4Mi1lNDM2LTM2OTNhZTQwMDllNCIsImlkZW50aXlJZCI6NTMwMX0.91kfMumbC_WGx7cTr6Sz-EEEeqZkhILstV5PdBOHzJ4",
    };
    return config;
  },
  function (error) {
    console.log(error);
    return Promise.reject(error);
  }
);

request.interceptors.response.use(
  function (res) {
    if (res.data instanceof Blob) {
      return res.data;
    } else if (res.status === 200) {
      return res.data || res.body;
    } else {
      // showFailToast(res.data.message);
    }
  },
  function (error) {
    // showFailToast("请求失败");
    return Promise.reject(error);
  }
);
export default request;
